package automata;

import automatagen.Automata;
import java.util.*;

public class Tdc_automata
{
  protected static String nl;
  public static synchronized Tdc_automata create(String lineSeparator)
  {
    nl = lineSeparator;
    Tdc_automata result = new Tdc_automata();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "//*************************************************************************\\\\" + NL + "//===---> tdc_automata_";
  protected final String TEXT_2 = ".cpp" + NL + "//*************************************************************************\\\\" + NL + "//*************************************************************************\\\\" + NL + "//*********** \t\t        UFPE/Cin - Greco\t\t***********\\\\" + NL + "//*********** \t\t http://www.cin.ufpe.br/~greco \t\t***********\\\\" + NL + "//***********\t\t\t\t\t\t\t***********\\\\" + NL + "//***********\t\t\t\t\t\t\t***********\\\\" + NL + "//*********** \t\t    By Rafael Melo Macieira\t\t***********\\\\" + NL + "//***********\t\t\t\t\t\t\t***********\\\\" + NL + "//***********\t\t    E-mail: rmm2@cin.ufpe.br\t\t***********\\\\" + NL + "//*************************************************************************\\\\" + NL + "//*************************************************************************\\\\" + NL + "//===---> Automata for the temporal check of the" + NL + "//===---> ";
  protected final String TEXT_3 = " service's" + NL + "//*************************************************************************\\\\" + NL + "\\" + NL + "\\" + NL + "" + NL + "#include <stdio.h>" + NL + "#include \"headers/tdc_automata_";
  protected final String TEXT_4 = ".h\"" + NL + "#include \"headers/address.h\"" + NL + "" + NL + "void TDC_Automata_";
  protected final String TEXT_5 = "::printRejection(StateID stateID) {" + NL + "" + NL + "};" + NL + "" + NL + "int TDC_Automata_";
  protected final String TEXT_6 = "::checkState(StateID stateID) {" + NL + "    return 0;" + NL + "};" + NL + "" + NL + "int TDC_Automata_";
  protected final String TEXT_7 = "::checkInitialState() {" + NL + "    return checkState(INITIAL_STATE);" + NL + "};" + NL + "" + NL + "TDC_Automata_";
  protected final String TEXT_8 = "::StateID TDC_Automata_";
  protected final String TEXT_9 = "::getNextState(StateID stateID) {" + NL + "    switch (stateID) {" + NL + "        case In:" + NL + "            if (access_type == 0) {" + NL + "                return In;" + NL + "            } else {" + NL + "                if (*lcd_var_data_cmd == 1) {" + NL + "                    return P1;" + NL + "                }" + NL + "            }" + NL + "            break;" + NL + "        case P1:" + NL + "            if (access_type == 0) {" + NL + "                return P1;" + NL + "            } else {" + NL + "                if (*lcd_var_cmd == 1) {" + NL + "                    return P2;" + NL + "                }" + NL + "            }" + NL + "            break;" + NL + "        case P2:" + NL + "            if (access_type == 0) {" + NL + "                return P2;" + NL + "            } else {" + NL + "                if (*lcd_var_cmd == 17) {" + NL + "                    return P3;" + NL + "                }" + NL + "            }" + NL + "            break;" + NL + "        case P3:" + NL + "            if (access_type == 0) {" + NL + "                return P3;" + NL + "            } else {" + NL + "                if (*lcd_var_cmd == 3) {" + NL + "                    return P4;" + NL + "                }" + NL + "            }" + NL + "            break;" + NL + "        case P4:" + NL + "            if (access_type == 0) {" + NL + "                return P4;" + NL + "            } else {" + NL + "                if (*lcd_var_cmd == 19) {" + NL + "                    return P5;" + NL + "                }" + NL + "            }" + NL + "            break;" + NL + "        case P5:" + NL + "            if (access_type == 0) {" + NL + "                return P5;" + NL + "            } else {" + NL + "                if (*lcd_var_cmd == 33) {" + NL + "                    return A;" + NL + "                }" + NL + "            }" + NL + "            break;" + NL + "        case A:" + NL + "            if (access_type == 0) {" + NL + "                return A;" + NL + "            } else {" + NL + "                return R;" + NL + "            }" + NL + "            break;" + NL + "    }" + NL + "    return R;" + NL + "};" + NL + "" + NL + "int TDC_Automata_";
  protected final String TEXT_10 = "::runStep(bool access_type, VarList* mainVarList) {" + NL + "    //unsigned int *currentVar= currentVarList->getVar();" + NL + "    //*currentVar =" + NL + "    this->access_type = access_type;" + NL + "    this->refreshVariables(mainVarList);" + NL + "    StateID tmp_currentState = this->getNextState(currentState);" + NL + "    //printf(\"Entrou!!\\n\");" + NL + "    switch (tmp_currentState) {" + NL + "        case A:" + NL + "            //printf(\"Accepted!\\n\");" + NL + "            this->currentState = tmp_currentState;" + NL + "            return 1;" + NL + "            break;" + NL + "        case R:" + NL + "            printf(\"Rejected!\\n\");" + NL + "            this->currentState = tmp_currentState;" + NL + "            return -1;" + NL + "            break;" + NL + "        default:" + NL + "            this->currentState = tmp_currentState;" + NL + "            return 0;" + NL + "    }" + NL + "};" + NL + "" + NL + "void TDC_Automata_";
  protected final String TEXT_11 = "::refreshVariables(VarList* mainVarList) {" + NL + "    lcd_var_cmd = mainVarList->getVarListByPlatformAddr(mainVarList,LCD_VAR_CMD_ADDR)->getVar(); //50" + NL + "    lcd_var_data_cmd = mainVarList->getVarListByPlatformAddr(mainVarList,LCD_VAR_DATA_CMD_ADDR)->getVar(); //51" + NL + "    //printf(\"\\n%p e %p\\n\", lcd_var_cmd,lcd_var_data_cmd);" + NL + "};" + NL + "" + NL + "void TDC_Automata_";
  protected final String TEXT_12 = "::reset(){" + NL + "\tthis->currentState = In;" + NL + "};" + NL + "" + NL + "TDC_Automata_";
  protected final String TEXT_13 = "::TDC_Automata_";
  protected final String TEXT_14 = "(VarList* mainVarList) : TDC_Automata(\"";
  protected final String TEXT_15 = "\"){//, mainVarList) {" + NL + "    this->refreshVariables(mainVarList);" + NL + "}";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    Automata automata = (Automata)argument;
    stringBuffer.append(TEXT_1);
    stringBuffer.append(automata.getName());
    stringBuffer.append(TEXT_2);
    stringBuffer.append(automata.getName());
    stringBuffer.append(TEXT_3);
    stringBuffer.append(automata.getName());
    stringBuffer.append(TEXT_4);
    stringBuffer.append(automata.getName());
    stringBuffer.append(TEXT_5);
    stringBuffer.append(automata.getName());
    stringBuffer.append(TEXT_6);
    stringBuffer.append(automata.getName());
    stringBuffer.append(TEXT_7);
    stringBuffer.append(automata.getName());
    stringBuffer.append(TEXT_8);
    stringBuffer.append(automata.getName());
    stringBuffer.append(TEXT_9);
    stringBuffer.append(automata.getName());
    stringBuffer.append(TEXT_10);
    stringBuffer.append(automata.getName());
    stringBuffer.append(TEXT_11);
    stringBuffer.append(automata.getName());
    stringBuffer.append(TEXT_12);
    stringBuffer.append(automata.getName());
    stringBuffer.append(TEXT_13);
    stringBuffer.append(automata.getName());
    stringBuffer.append(TEXT_14);
    stringBuffer.append(automata.getName());
    stringBuffer.append(TEXT_15);
    return stringBuffer.toString();
  }
}
